package com.himore.api.web.controller.modules;

import com.himore.api.common.annotation.Log;
import com.himore.api.common.core.controller.BaseController;
import com.himore.api.common.core.domain.AjaxResult;
import com.himore.api.common.core.page.TableDataInfo;
import com.himore.api.common.enums.BusinessType;
import com.himore.api.common.utils.poi.ExcelUtil;
import com.himore.api.web.model.TCommentPicture;
import com.himore.api.web.service.ITCommentPictureService;
import com.himore.api.web.service.ITSysCommentService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * 评论图片Controller
 * 
 * @author ruoyi
 * @date 2021-05-12
 */
@Api(tags = "评论图片管理")
@Controller
@RequestMapping("/system/comment/picture")
public class TCommentPictureController extends BaseController
{
    private String prefix = "system/comment/picture";

    @Autowired
    private ITCommentPictureService tCommentPictureService;

    @GetMapping()
    public String picture()
    {
        return prefix + "/picture";
    }

    /**
     * 查询评论图片列表
     */
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TCommentPicture tCommentPicture)
    {
        startPage();
        List<TCommentPicture> list = tCommentPictureService.selectTCommentPictureList(tCommentPicture);
        return getDataTable(list);
    }

    /**
     * 导出评论图片列表
     */
    @Log(title = "评论图片", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TCommentPicture tCommentPicture)
    {
        List<TCommentPicture> list = tCommentPictureService.selectTCommentPictureList(tCommentPicture);
        ExcelUtil<TCommentPicture> util = new ExcelUtil<TCommentPicture>(TCommentPicture.class);
        return util.exportExcel(list, "评论图片数据");
    }



    /**
     * 新增保存评论图片
     */
    @Log(title = "评论图片", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(TCommentPicture tCommentPicture)
    {
        return toAjax(tCommentPictureService.insertTCommentPicture(tCommentPicture));
    }

    /**
     * 修改评论图片
     */
    @GetMapping("/edit/{picId}")
    public String edit(@PathVariable("picId") Long picId, ModelMap mmap)
    {
        TCommentPicture tCommentPicture = tCommentPictureService.selectTCommentPictureById(picId);
        mmap.put("tCommentPicture", tCommentPicture);
        return prefix + "/edit";
    }

    /**
     * 修改保存评论图片
     */
    @Log(title = "评论图片", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TCommentPicture tCommentPicture)
    {
        return toAjax(tCommentPictureService.updateTCommentPicture(tCommentPicture));
    }

    /**
     * 删除评论图片
     */
    @Log(title = "评论图片", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(tCommentPictureService.deleteTCommentPictureByIds(ids));
    }
}
